﻿using System;
using CDOP.Model;
using CDOP.Utility;

namespace CDOP
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void BtnSubmitClick(object sender, EventArgs e)
        {
            var loggedUser = new Authentication().GetAuthenticationByUserName(txtUserName.Text);
            if (loggedUser == null)
            {
                lblStatus.Text = "No users found with that user name";
            }
            else
            {
                var encrytedpassword = Helper.Encrypt(txtPassword.Text);
                if (loggedUser.Password == encrytedpassword)
                {
                    Session["LoggedUser"] = loggedUser.UserDetails;
                    //if (loggedUser.UserDetails.UserType.Type.ToLower() == "admin")
                    //    Response.Redirect("Default.aspx");
                    //else
                        Response.Redirect("Home.aspx");
                }
                else
                {
                    lblStatus.Text = "Incorrect password entered";
                }
            }
        }
    }
}